﻿<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet
  version="1.0"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:x="http://schemas.microsoft.com/xps/2005/06/resourcedictionary-key"
  >
  <xsl:output method="xml" version="1.0" omit-xml-declaration="yes" indent="yes" encoding="utf-8"  />
  
  <xsl:include href="include/Slices.xslt"/>
  <xsl:key name="ProjectByClient" match="ProjectPerformance" use="ClientName" />
  

 
  <xsl:template match="/">

    <FlowDocument PageWidth="21cm"
      PagePadding="60,40,40,40"
      PageHeight="29.7cm"
      ColumnWidth="21 cm">

      <xsl:call-template name="StyleSettings"/>


      <xsl:call-template name="Header">
        <xsl:with-param name="isProjectHeader" select="0"/>
        <xsl:with-param name="context" select="/ProjectPerformanceDataSet"/>
        <xsl:with-param name="type" select="'Organization Performance - By Client'"/>
      </xsl:call-template>


      <xsl:call-template name="Summary"/>
      
      <xsl:for-each select="/ProjectPerformanceDataSet/ProjectPerformance[ count(.|key('ProjectByClient', ClientName)[1]) = 1]" >
        <xsl:sort data-type="number" order="descending" select="sum(key('ProjectByClient', ClientName)/PctIncome)"/>
        <xsl:sort data-type="number" select="Status"/>
        <xsl:variable name="clientName" select="ClientName"/>
        <Paragraph Style="{{StaticResource TitleParagraph}}">
          <LineBreak/>
          <xsl:value-of select="ClientName"/> (<xsl:value-of select="count(/ProjectPerformanceDataSet/ProjectPerformance[ClientName=$clientName])"/> projects, 
          <xsl:value-of select="format-number(sum(/ProjectPerformanceDataSet/ProjectPerformance[ClientName=$clientName]/PctIncome),'#.##0,0','pt-br-Decimal')"/>% income)
      </Paragraph>


        <Table Style="{{StaticResource NoBorderTable}}">
          <Table.Columns>
            <TableColumn Width="300"  />
            <TableColumn  />
            <TableColumn  />
            <TableColumn  />
            <TableColumn  />
            <TableColumn  />
          </Table.Columns>
          <TableRowGroup>
            <xsl:for-each select="/ProjectPerformanceDataSet/ProjectPerformance[ClientName=$clientName]">
              <xsl:sort data-type="number" order="descending" select="PctIncome"/>
              <xsl:sort data-type="number" select="Status"/>
              <xsl:call-template name="ProjectPerformance"/>
            </xsl:for-each>
          </TableRowGroup>
        </Table>
        
      </xsl:for-each>
      
      
              

    </FlowDocument>

  </xsl:template>


  

</xsl:stylesheet>